package jaux.tank.bean.dto;

import jaux.tank.bean.entity.system.Dept;
import jaux.tank.bean.vo.node.ZTreeNode;
import java.util.Objects;
import lombok.Data;

@Data
public class DeptDto implements EntityDto<Dept> {

	private String id;
	private Integer num;

	private IdDto parentDept;
	private String simplename;
	private String fullname;
	private String tips;
	private Integer version;
	
	public DeptDto() {}
	public DeptDto(Dept dept) {
		copyEntity(dept);
	}
	

	@Override
	public void copyEntity(Dept dept) {
        this.setId(dept.getId());
        this.setNum(dept.getNum());
        if (dept.getParentDept() != null && dept.getParentDept().getId()!=null) {
            this.setParentDept(new IdDto(dept.getParentDept().getId()));
        }
        this.setSimplename(dept.getSimplename());
        this.setFullname(dept.getFullname());
        this.setTips(dept.getTips());
        this.setVersion(dept.getVersion());
	}

	@Override
	public Dept toEntity() {
		Dept dept = new Dept();
		dept.setId(this.getId());
		dept.setNum(this.getNum());
		if(this.parentDept!=null 
				&& this.parentDept.getId()!=null
				&& ! this.parentDept.getId().equals(ZTreeNode.DEFAULT_ROOT_ID)) {
			Dept pDept = new Dept();
			pDept.setId(this.parentDept.getId());
			dept.setParentDept(pDept );
		}
		dept.setSimplename(this.getSimplename());
		dept.setFullname(this.getFullname());
		dept.setTips(this.getTips());
		dept.setVersion(this.getVersion());
		return dept;
	}

}
